package br.com.android.games.daedal;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

/**
 * Tela principal para a seleção do modo de jogo
 * 
 * @since 2013
 * @author <a href="mailto:fernando.schindler@gmail.com">Fernando Schindler</a>
 */
public class SelectScreen extends Activity {
	
	private static Typeface font = null;

	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/**
		 * Desligar o titulo da janela
		 */
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		/**
		 * Ajustar para ser tela inteira
		 */
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		/**
		 * Ajustar esquema de volume
		 */
		setVolumeControlStream(AudioManager.STREAM_MUSIC);

		/**
		 * Ajustar LAYOUT Principal
		 */
		setContentView(R.layout.select);	
		
		/**
		 * Criar fonte
		 */
		font = Typeface.createFromAsset(getResources().getAssets(), "jrha.ttf");
		
		/**
		 * Configurar botão do modo classico
		 */
		configClassicBnt();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onBackPressed()
	 */
	@Override
	public void onBackPressed() {		
		new AlertDialog.Builder(this)
				.setIcon(android.R.drawable.ic_dialog_alert)
				.setTitle(R.string.app_name)
				.setMessage(R.string.app_on_exit)
				.setPositiveButton(android.R.string.yes,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								finish();
							}

						}).setNegativeButton(android.R.string.no, null)
						.show();
	}
	
	/**
	 * Ir para o modo de jogo avançado
	 * @param v
	 */
	public void onAdvanced(View v) {
		Intent intent = new Intent(this, DaedalDotsActivity.class);
		intent.putExtra(DaedalDotsActivity.IS_CLASSIC_MODE, false);
		startActivity(intent);
	}
	
	/**
	 * Ir para o modo de jogo clássico
	 * @param v
	 */
	public void onClassic(View v) {
		startActivity(new Intent(this, DaedalDotsActivity.class));
	}
	
	/**
	 * Ir para o modo de jogo avançado
	 * @param v
	 */
	public void onConfiguration(View v) {
		startActivity(new Intent(this, Preferences.class));
	}
	
	/**
	 * Ir para tela about
	 * @param v
	 */
	public void onAbout(View v) {
		v.setVisibility(View.INVISIBLE); 
		v.postInvalidate();		
		About about = new About(this, v);	
		about.show();
	}
	
	/**
	 * Ajustar a fonte
	 * @param views
	 */
	public static void setDefaultFont(View[] views) {
		if (null != font)
			for (View v : views) {
				if (v instanceof TextView) {
					((TextView) v).setTypeface(font);
				} else if (v instanceof Button) {
					((Button) v).setTypeface(font);
				}
			}
	}
	
	/**
	 * 
	 */
	public  void configClassicBnt() {
		
		View views [] = {
				findViewById(R.id.bnt_classic_mode),
				findViewById(R.id.bnt_advance_mode),
				findViewById(R.id.txt_select_mode)
		};
		
		setDefaultFont(views);
	}	
}
